package cn.kbyue.testcasedemo.controller;

import cn.kbyue.testcasedemo.service.ExpireService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
@RequiredArgsConstructor
@RequestMapping("/time")
public class TimeController {

    private final ExpireService expireService;

    @GetMapping("/expire")
    public ResponseEntity<String> expire(LocalDateTime tokenTime) {
        if (expireService.isExpired(tokenTime)) {
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("token 已过期!");
        }
        return ResponseEntity.ok("success");
    }

}
